package cn.itlaobing.springbootdemo.web.controller;

import cn.itlaobing.springbootdemo.entity.SystemAccount;
import cn.itlaobing.springbootdemo.reponsitory.SystemAccountRepository;
import cn.itlaobing.springbootdemo.service.SystemAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/systemAccounts")
public class SystemAccountController extends BaseController{

    @Autowired
    private SystemAccountRepository repository;


    @Autowired
    private SystemAccountService systemAccountService;

    /**
     * pageable 从请求参数中获取页码
     *  page =0
     *  size = 20 默认
     *  sort = id,desc
     *
     * @param pageable
     * @return
     */
    @RequestMapping(method = {RequestMethod.GET,RequestMethod.POST})  //同时支持GET与POST
    public String index(@RequestParam(required = false) String nameOrAccount, Pageable pageable, Model model){
        //按照分页查询
        Page<SystemAccount> systemAccountPage= systemAccountService.findByStudentNameOrAccount(nameOrAccount,pageable);
        model.addAttribute("systemAccountPage",systemAccountPage);
        return "/systemAccount/index";
    }


}
